//package org.jeecg.modules.deepseek.tools;
//
//import io.swagger.v3.oas.annotations.media.Schema;
//import jakarta.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.ai.tool.annotation.Tool;
//import org.springframework.ai.vectorstore.SearchRequest;
//import org.springframework.ai.vectorstore.VectorStore;
//import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.ai.document.Document;
//import org.springframework.context.annotation.Description;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.function.Function;
//
//@Slf4j
//@Configuration
//public class WebRedisTools {
//
//    @Resource
//    private VectorStore vectorStore;
//    //添加文本到向量数据库
//    public record NoteTextParsingRequest(
//            @Schema(description = "概述")
//            String noteText,
//            @Schema(description = "标题")
//            String noteTitle,
//            @Schema(description = "内容")
//            String noteContent,
//            @Schema(description = "表述位置")
//            String notePosition,
//            @Schema(description = "时间")
//            String noteDate,
//            @Schema(description = "类型")
//            String noteType
//    ){
//
//    }
//
//    public record RedisQuery( @Schema(description = "查询文本")
//                              String key
//    ) {
//    }
//    public record RedisQueryResult( @Schema(description = "查询结果")
//                                    String content
//    ) {
//
//    }
//    @Bean
//    @Description("查询向量数据库,如果查询不到就返回空字符串")
//    public Function<RedisQuery, RedisQueryResult> getRedisQuery() {
//        return (request) -> {
//            FilterExpressionBuilder b = new FilterExpressionBuilder();
//            String key = request.key();
//            List<Document> results = this.vectorStore.similaritySearch(
//                    SearchRequest.builder().query(key).topK(5).similarityThresholdAll()
//                            .filterExpression(b.eq("noteTitle","work").build()).build());
//            results.forEach(aar ->{
//                log.info("查询文本：{}",aar.getText());
//                aar.getMetadata().forEach((k,v)->{
//                    log.info("k:{},v:{}",k,v);
//                });
//            });
//            if (results.isEmpty()) {
//                return new RedisQueryResult("");
//            }
//            return new RedisQueryResult(results.get(0).toString());
//        };
//    }
//
//    public Document createDocumentFromNoteRequest(NoteTextParsingRequest request) {
//        // 创建元数据Map
//        Map<String, Object> metadata = new HashMap<>();
//        metadata.put("noteText", request.noteText());
//        metadata.put("noteTitle", request.noteTitle());
//        metadata.put("notePosition", request.notePosition());
//        metadata.put("noteDate", request.noteDate());
//        metadata.put("noteType", request.noteType());
//
//        // 使用noteContent作为文档内容，其他作为元数据创建Document
//        return new Document(request.noteContent(), metadata);
//    }
//    @Bean
//    @Description("按照规定格式插入向量数据库,如果文本没有字段的话，根本文本来填充")
//    public Function<NoteTextParsingRequest, Boolean> addVectorStoreContent() {
//        return (request) -> {
//            vectorStore.add(List.of(createDocumentFromNoteRequest(request)));
//            return true;
//        };
//    }
//}
